//登录
function login(){
    var userName=$('#txtName').val();
    if(userName){
        localStorage.chat_name=userName;
        location.href='index.html';
    }else{
        alert('名字不能为空！');
    }
}

$(document)
    //点击登录
    .on('click', '#btnLogin', login)
    //回车登录
    .on('keydown', '#txtName', function(e){
        if(e.keyCode==13){
            login();
        }
    })
;